package cn.itcast.order;

import cn.itcast.feign.clients.UserClient;
import cn.itcast.feign.config.DefaultFeignConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author yuanbailin
 * @since v1.0  2022-03-25 23:49
 */
@SpringBootApplication
@MapperScan("cn.itcast.order.mapper")
//开启feign自动装配,日志级别，指定加载需要使用的client
@EnableFeignClients(defaultConfiguration = DefaultFeignConfiguration.class, clients = UserClient.class)
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    @Bean
    @LoadBalanced   //负载均衡，默认轮询
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    //手动配置负载均衡策略为随机，在这里配置时是全局配置，所有的order服务都是这种策略
    //在代码里面配置的权重会比在yml文件配置的权重高，会使用这里的配置
    /*@Bean
    public IRule rule(){
        return new RandomRule();
    }*/

}
